package com.h3bpm.kumhosunny.h3bpm;

import OThinker.H3.Controller.ControllerBase;
import com.alibaba.fastjson.JSONObject;
import com.h3bpm.kumhosunny.common.utils.SqlUtil;
import data.DataColumn;
import data.DataRow;
import data.DataTable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.xml.crypto.Data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @authormi
 * @date2019/11/22
 */
@Controller
@RequestMapping(value="/Portal/toolbarJctController")
public class ToolbarController extends ControllerBase {


    @RequestMapping("/jctShowButton")
    @ResponseBody
    public JSONObject jctShowButton() {

        JSONObject result= new JSONObject();
        try {
            result.put("status","200");
            result.put("data", getUserValidator().getUser().getIsAdministrator());
            return result;
        } catch (Exception e) {
            result.put("status","500");
            e.printStackTrace();
        }
        return result;
    }


    @RequestMapping("/getChildTable")
    @ResponseBody
    public JSONObject getChildTable(String tabCode ,String bizObjectId) {
        JSONObject result = new JSONObject();
        String getChildTableSql = "  select  *  from  i_"+tabCode+"  where ParentObjectID = '"+bizObjectId+"' " ;
        result.put("status","200");
        result.put("data","");
        try {
               DataTable dataTable = SqlUtil.doQuery(getChildTableSql);
               List list= new ArrayList();
                if(dataTable!=null &&  dataTable.getEntityRows()!=null && dataTable.getEntityRows().size()>0){
                    for(DataRow dataRow : dataTable.getEntityRows()){
                     Map<String,Object> map =new HashMap<String,Object>(4);
                       for (int i =0 ;i< dataTable.getColumns().size();i++){
                           DataColumn column = dataTable.getColumns().get(i);
                           Object object =  dataRow.getObject(column.getColumnName());
                           if(object!=null) {
                               map.put(column.getColumnName(), dataRow.getObject(column.getColumnName()));
                           }else{
                               map.put(column.getColumnName(),"");
                           }
                       }
                        list.add(map);
                    }
                }
                result.put("data",list);
        } catch (Exception e) {
            result.put("status","500");
            result.put("data","系统异常");
            e.printStackTrace();
        }
        return result;

    }




    @Override
    public String getFunctionCode() {
        return null;
    }
}
